package com.itbbs.email.controller;

import com.itbbs.email.service.api.EmailService;
import com.itbbs.exception.CustomizeException;
import com.itbbs.result.Result;
import com.itbbs.result.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 邮件服务的接口
 * @createTime 2021年06月21日 11:00:00
 */
@Api(tags = "邮件服务")
@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private EmailService emailService;

    /**
     * 对应登陆注册找回密码的邮箱验证码进行统一的发送
     *
     * @param emailAddress 用户的邮箱
     * @param type 邮件的类型
     */
    @ApiOperation("发送邮件")
    @PostMapping("/send")
    public Result sendEmail(@RequestParam("emailAddress") String emailAddress,@RequestParam("type") String type){
        // TODO 对邮箱进行解密
        if (StringUtils.isEmpty(emailAddress) || StringUtils.isEmpty(type)){
            throw new CustomizeException(ResultCodeEnum.PARAM_ERROR);
        }
        emailService.sendEmail(emailAddress,type);
        return Result.ok();
    }
}
